import type { App } from 'vue';

import { hasPerm } from './permission';

// 全局注册 directive
export function setupDirective(app: App<Element>) {
  // 使 v-hasPerm 在所有组件中都可用
  app.directive('hasPerm', hasPerm);
  
  app.directive('no-more-click', {
    beforeMount(el, binding) {
      el.addEventListener('click', () => {
        el.classList.add('is-disabled');
        el.disabled = true;
        setTimeout(() => {
          el.disabled = false;
          el.classList.remove('is-disabled');
        }, 10000);
      });
    },
    updated(el) {
      el.disabled = false;
      el.classList.remove('is-disabled');
    }
  });
  
}
